﻿// -----------------------------------------------------------------------
// <copyright file="MessageProvider.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Metal.Resources
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Xml;

    /// <summary>
    /// Provides internationalized messages based on ID
    /// </summary>
    public static class MessageProvider
    {
        /// <summary>Used to load a xml from file</summary>
        private static XmlDocument document = new XmlDocument();

        /// <summary>Get text resource based on a resource id</summary>
        /// <param name="resourceID">Name of the resource</param>
        /// <returns>The resource text</returns>
        public static string GetMessage(string resourceID)
        {
            try
            {
                XmlNodeList resourceList = document.SelectNodes("Language/" + resourceID);
                string strResource = resourceList.Item(0).Attributes.GetNamedItem("text").Value;

                if (strResource != null)
                {
                    return strResource;
                }
                else
                {
                    return string.Empty;
                }
            }
            catch
            {
                return string.Empty;
            }
        }

        /// <summary>Set language</summary>
        /// <param name="language">Language file name (without extension)</param>
        public static void LoadLanguageFile(string language)
        {
            try
            {
                document.Load(Config.Paths.LanguageFolder + language + ".xml");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
